home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / DINKDEMO / DC_TEXTE / TEDITMAI.C < prev    next >
C/C++ Source or Header  |  1992-07-08  |  4KB  |  175 lines

  1. /*
  2.     File:        ScribleMainProgram.c
  3.  
  4.     Written by:    Mark Gross
  5.  
  6.     Copyright:    ⌐ 1992 by Applied Technical Software, all rights reserved.
  7.     Use at your own risk.
  8.  
  9. */
  10.  
  11. //
  12. // this is the model main function modual for the typical DinkClass
  13. // application
  14. //
  15.  
  16. #include "DTEditApp.h"
  17. #include "DTEditDoc.h"
  18. #include <DinkUtils.h>
  19.  
  20. //
  21. // Requiered apple event prototypes
  22. //
  23.  
  24. void DoAEInstallation(void);
  25.  
  26. pascal OSErr HandleQUIT( AppleEvent *theAppleEvent, AppleEvent *reply,
  27.                          long myRefCon);
  28. pascal OSErr HandleOAPP( AppleEvent *theAppleEvent, AppleEvent *reply, 
  29.                          long myRefCon);
  30. pascal OSErr HandlePDOC( AppleEvent *theAppleEvent, AppleEvent *reply,
  31.                          long myRefCon);
  32. pascal OSErr HandleODOC( AppleEvent *theAppleEvent, AppleEvent *reply,
  33.                          long myRefCon);
  34.  
  35.  
  36. main()
  37. {
  38.     DApplication    *theApp;
  39.     
  40.     InitToolBox(5);
  41.  
  42.     if(!System7Available() )
  43.         DebugStr( "\p No System 7!!" );
  44.  
  45.     DEventHandler::gApplication = NULL;// to make sure no messages get sent to gApplication 
  46.                                     // before it is instanicated.  otherwise the Application
  47.                                     // object will be sending install handler message to itself
  48.                                     // befor it is fully instaniated.
  49.     
  50.     theApp = new DTEditApp;
  51.     
  52.     DEventHandler::gApplication = theApp;
  53.     DEventHandler::gPassItOn = TRUE;
  54.  
  55.     theApp->fCreator = 'MkGr';
  56.     theApp->fClipType = 'TEXT';
  57.     theApp->fMainFileType = 'TEXT';
  58.  
  59.     DoAEInstallation();// the AE-handler procs refrence gApplication 
  60.                         // so I'm initializing the AEvents after I have
  61.                         // a valid gApplication
  62.     
  63.     
  64.     if(theApp->InitApp() )
  65.     {            
  66.         theApp->MakeDDoc(FALSE);
  67.         theApp->EventLoop();
  68.         theApp->CleanUp();
  69.     }
  70.     ExitToShell();    //last good bye kiss
  71. }// the end
  72.  
  73.  
  74.  
  75.  
  76. void DoAEInstallation(void)
  77. {
  78.  
  79.     AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments,
  80.                             (EventHandlerProcPtr)HandleODOC, 0, false);
  81.  
  82.     AEInstallEventHandler( kCoreEventClass, kAEQuitApplication,
  83.                             (EventHandlerProcPtr)HandleQUIT, 0, false);
  84.  
  85.     AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments,
  86.                             (EventHandlerProcPtr)HandlePDOC, 0, false);
  87.  
  88.     AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,
  89.                             (EventHandlerProcPtr)HandleOAPP, 0, false);
  90.  
  91. }                            
  92.  
  93.  
  94.  
  95. pascal OSErr HandleQUIT( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  96. {
  97.     OSErr myErr;
  98.     
  99.     myErr = RequiredCheck( theAppleEvent);
  100.     if (myErr) 
  101.         return myErr;
  102.     
  103.     DEventHandler::gApplication->fDone = true;
  104.     return noErr;
  105. }
  106.  
  107.  
  108.  
  109. pascal OSErr HandleOAPP( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  110. {
  111.     OSErr myErr;
  112.  
  113.     myErr = RequiredCheck( theAppleEvent);
  114.     if (myErr) 
  115.         return myErr;
  116.     
  117.     return noErr;
  118. }
  119.  
  120.  
  121.  
  122. pascal OSErr HandlePDOC( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  123. {
  124.     OSErr myErr;
  125.  
  126.     myErr = RequiredCheck( theAppleEvent);
  127.     if (myErr) 
  128.         return myErr;
  129.     
  130.     return errAEEventNotHandled;
  131. }
  132.  
  133.  
  134. pascal OSErr HandleODOC( AppleEvent *theAppleEvent, AppleEvent *reply, long myRefCon)
  135. {
  136.     OSErr myErr;
  137.     AEDescList  docList;
  138.     FSSpec        myFSS;
  139.     long        i;
  140.     long        itemsInList;
  141.     AEKeyword    theKeyWord;
  142.     DescType    typeCode;
  143.     Size        actualSize;
  144.     WindowPtr    docWindow;
  145.     DDocument* newDoc;
  146.  
  147.     myErr = AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
  148.     if ( myErr)
  149.         return(myErr);
  150.  
  151.     myErr = RequiredCheck( theAppleEvent);
  152.     if (myErr) 
  153.         return myErr;
  154.  
  155.  
  156.     myErr = AECountItems(&docList, &itemsInList);
  157.     if (myErr) 
  158.         return myErr;
  159.         
  160.     for (i = 1; ((i <= itemsInList) && (!myErr)); ++i) 
  161.     {
  162.         myErr = AEGetNthPtr( &docList, i, typeFSS, &theKeyWord,    &typeCode, 
  163.             (Ptr)&myFSS, sizeof(FSSpec), &actualSize );
  164.         
  165.         if (myErr) 
  166.             return myErr;
  167.         
  168.         newDoc = new DTEditDoc;
  169.         if (newDoc)
  170.             newDoc->AEInitDoc(&myFSS); 
  171.     }
  172.     return noErr;
  173. }
  174.  
  175.